Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/qp #5012

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Refactor/qp #5012

merged 3 commits into from
Oct 30, 2024

Conversation

CamronStaley
Copy link
Contributor

@CamronStaley CamronStaley commented Oct 30, 2024

What changes are proposed in this pull request?

refactor toast component to core

How is this patch tested? If it is not, please explain why.

running server locally and changing is shown to True by default to make the popup appear

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Introduced QueryPerformanceToast component to enhance the DatasetPage with performance notifications.
  • Improvements

    • Enhanced readability and maintainability of the QueryPerformanceToast component with formatting adjustments.
    • Added a new data-cy attribute to the dismiss button for improved testing capabilities.
  • Accessibility

    • Made QueryPerformanceToast available for import across the application through the core components index.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The changes involve modifications to the DatasetPage.tsx, QueryPerformanceToast.tsx, and index.ts files. The DatasetPage now imports QueryPerformanceToast from the @fiftyone/core package instead of a local path, integrating it into the component's render output. The QueryPerformanceToast component has been reformatted for better readability and includes a new data-cy attribute for testing purposes. Additionally, it has been added as a default export in the index.ts file, enhancing its accessibility across the application.

Changes

File Change Summary
app/packages/app/src/pages/datasets/DatasetPage.tsx - Removed import of QueryPerformanceToast from local path.
- Added import from @fiftyone/core.
- Integrated QueryPerformanceToast into the component's return statement.
app/packages/core/src/components/QueryPerformanceToast.tsx - Reformatted layout object for readability.
- Updated button color to use dynamic value.
- Added data-cy attribute to dismiss button.
- Reformatted Typography component properties for consistency.
app/packages/core/src/components/index.ts - Added export statement for QueryPerformanceToast as a default export.

Possibly related PRs

  • make it pretty #4999: This PR modifies the QueryPerformanceToast component, which is directly related to the changes made in the main PR that also involves the QueryPerformanceToast component.
  • Lightmode for Query Performance Toast #5004: This PR introduces light mode support for the QueryPerformanceToast, which is relevant as it pertains to the same component modified in the main PR.
  • Merge release/v1.1.0 to develop #5007: This PR also modifies the QueryPerformanceToast component, aligning with the changes in the main PR regarding the visibility and styling of the toast notifications.

Suggested reviewers

  • minhtuev
  • ritch
  • imanjra
  • benjaminpkane

🐇 In the code, I hop and play,
A toast for queries, brightening the day.
With colors that change and attributes new,
My components dance, oh so true!
From local paths, we’ve taken flight,
In the core, they shine so bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@sashankaryal sashankaryal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
app/packages/core/src/components/index.ts (1)

12-12: LGTM! Good architectural decision.

Moving the QueryPerformanceToast to core and exporting it through the barrel file improves modularity and reusability. The export follows the established pattern and maintains consistency with other component exports.

app/packages/core/src/components/QueryPerformanceToast.tsx (1)

Line range hint 1-124: Consider enhancing TypeScript usage and constants management.

  1. The SHOWN_FOR constant could be moved to a constants file for better maintainability.
  2. Consider adding proper TypeScript types for the component props and theme values.
// types.ts
export interface QueryPerformanceToastProps {
  portalElementId?: string;
}

// constants.ts
export const TOAST_CONSTANTS = {
  SHOWN_DURATION: 5000,
  PORTAL_ID: 'queryPerformance',
} as const;

Then update the component:

- const SHOWN_FOR = 5000;
+ import { TOAST_CONSTANTS } from './constants';
+ import type { QueryPerformanceToastProps } from './types';

- const QueryPerformanceToast = () => {
+ const QueryPerformanceToast: React.FC<QueryPerformanceToastProps> = ({
+   portalElementId = TOAST_CONSTANTS.PORTAL_ID
+ }) => {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 430c3f7 and 10cca75.

📒 Files selected for processing (3)
  • app/packages/app/src/pages/datasets/DatasetPage.tsx (1 hunks)
  • app/packages/core/src/components/QueryPerformanceToast.tsx (4 hunks)
  • app/packages/core/src/components/index.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/packages/app/src/pages/datasets/DatasetPage.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/QueryPerformanceToast.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/index.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (3)
app/packages/app/src/pages/datasets/DatasetPage.tsx (2)

Line range hint 108-108: LGTM! Proper placement of QueryPerformanceToast.

The component is correctly positioned alongside other global UI elements.


1-1: LGTM! Verify other imports of QueryPerformanceToast.

The import change aligns with moving the toast component to core.

Let's verify no other files are still importing from the old location:

✅ Verification successful

Import change is correctly implemented

The verification shows that:

  • QueryPerformanceToast is properly exported from @fiftyone/core
  • No other files are importing it from the old location
  • The only imports are from the new @fiftyone/core location
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining imports from the old location
rg "from ['\"].*components/QueryPerformanceToast['\"]"

Length of output: 60


Script:

#!/bin/bash
# Let's try a broader search for QueryPerformanceToast to find any remaining imports
rg "QueryPerformanceToast" -A 2 -B 2

Length of output: 3848

app/packages/core/src/components/QueryPerformanceToast.tsx (1)

77-77: LGTM! Good test coverage addition.

The data-cy attribute follows best practices for Cypress testing and uses a clear, descriptive identifier.

Comment on lines +98 to +102
sx={{
fontWeight: 500,
marginRight: "8px",
color: theme.text.primary,
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider memoizing Typography styles.

The sx object is recreated on every render. Consider using useMemo to optimize performance.

+ const titleTypographyStyles = useMemo(() => ({
+   fontWeight: 500,
+   marginRight: "8px",
+   color: theme.text.primary,
+ }), [theme.text.primary]);

  <Typography
    variant="subtitle1"
-    sx={{
-      fontWeight: 500,
-      marginRight: "8px",
-      color: theme.text.primary,
-    }}
+    sx={titleTypographyStyles}
  >

Committable suggestion was skipped due to low confidence.

Comment on lines +47 to +52
layout={{
bottom: "100px",
vertical: "bottom",
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider memoizing the layout object.

The layout object is recreated on every render. Consider using useMemo to optimize performance.

+ const layout = useMemo(() => ({
+   bottom: "100px",
+   vertical: "bottom",
+   horizontal: "center",
+   backgroundColor: theme.custom.toastBackgroundColor,
+ }), [theme.custom.toastBackgroundColor]);

  return createPortal(
    <Toast
      duration={SHOWN_FOR}
-      layout={{
-        bottom: "100px",
-        vertical: "bottom",
-        horizontal: "center",
-        backgroundColor: theme.custom.toastBackgroundColor,
-      }}
+      layout={layout}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
layout={{
bottom: "100px",
vertical: "bottom",
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}}
const layout = useMemo(() => ({
bottom: "100px",
vertical: "bottom",
horizontal: "center",
backgroundColor: theme.custom.toastBackgroundColor,
}), [theme.custom.toastBackgroundColor]);
return createPortal(
<Toast
duration={SHOWN_FOR}
layout={layout}
```
Note: The suggestion assumes that `useMemo` is imported from 'react'. If it's not already imported, you would need to add:
```typescript
import { useMemo } from 'react';

Comment on lines +62 to +67
sx={{
marginLeft: "auto",
backgroundColor: theme.primary.main,
color: theme.text.primary,
boxShadow: 0,
}} // Right align the button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove redundant comment and consider memoizing styles.

The comment "Right align the button" is redundant as it's describing what marginLeft: "auto" does. Also, consider memoizing the sx object.

+ const primaryButtonStyles = useMemo(() => ({
+   marginLeft: "auto",
+   backgroundColor: theme.primary.main,
+   color: theme.text.primary,
+   boxShadow: 0,
+ }), [theme.primary.main, theme.text.primary]);

  <Button
    variant="contained"
    size="small"
    onClick={() => {
      open(QP_MODE, "_blank")?.focus();
      setOpen(false);
    }}
-    sx={{
-      marginLeft: "auto",
-      backgroundColor: theme.primary.main,
-      color: theme.text.primary,
-      boxShadow: 0,
-    }} // Right align the button
+    sx={primaryButtonStyles}
  >

Committable suggestion was skipped due to low confidence.

@CamronStaley CamronStaley merged commit 701c0c9 into develop Oct 30, 2024
11 checks passed
@CamronStaley CamronStaley deleted the refactor/qp branch October 30, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants